﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTest
{
    [TestClass]
    public class UnitTestUC2
    {
        #region Test ValidateAmount
        public Boolean ValidateAmount(decimal amount)
        {
            if (amount > 5000000)
            {
                return false;
            }
            if (amount % 50000 != 0)
            {
                return false;
            }
            return true;
        }

        [TestMethod]
        public void UC2Validate1()
        {
            bool result = ValidateAmount(10000);
            Assert.AreEqual(result, false);
        }

        [TestMethod]
        public void UC2Validate2()
        {
            bool result = ValidateAmount(500000);
            Assert.AreEqual(result, true);
        }

        [TestMethod]
        public void UC2Validate3()
        {
            bool result = ValidateAmount(10000000);
            Assert.AreEqual(result, false);
        }
        #endregion

        #region Test CheckBalance
        public Boolean CheckBalane(decimal amount, decimal balance)
        {
            if (amount > balance)
            {
                return false;
            }
            return true;
        }
        
        [TestMethod]
        public void UC2TestCheckBalance1()
        {
            bool check = CheckBalane(4000000, 2000000);
            Assert.AreEqual(check,false);
        }

        [TestMethod]
        public void UC2TestCheckBalance2()
        {
            bool check = CheckBalane(1000000, 2000000);
            Assert.AreEqual(check,true);
        }
        #endregion
        
        #region Test MoneyInATM
        public Boolean CheckMoneyInATM(decimal amount, int ATM_loai500, int ATM_loai200, int ATM_loai100, int ATM_loai50, int ATM_loai20, int ATM_loai10)
        {
            int loai500 = 0;
            int loai200 = 0;
            int loai100 = 0;
            int loai50 = 0;
            int loai20 = 0;
            int loai10 = 0;
            decimal temp = 0;
            //Check type 500k
            temp = amount % 500000;
            loai500 = Convert.ToInt32((amount - temp) / 500000);
            if (ATM_loai500< loai500)
            {
                loai500 = ATM_loai500;
            }
            amount = amount - loai500 * 500000;
            //Check type 200k
            temp = amount % 200000;
            loai200 = Convert.ToInt32((amount - temp) / 200000);
            if (ATM_loai200< loai200)
            {
                loai200 = ATM_loai200;
            }
            amount = amount - loai200 * 200000;
            //Check type 100k
            temp = amount % 100000;
            loai100 = Convert.ToInt32((amount - temp) / 100000);
            if (ATM_loai100 < loai100)
            {
                loai100 = ATM_loai100;
            }
            amount = amount - loai100 * 100000;
            //Check type 50k
            temp = amount % 50000;
            loai50 = Convert.ToInt32((amount - temp) / 50000);
            if (ATM_loai50< loai50)
            {
                loai50 = ATM_loai50;
            }
            amount = amount - loai50 * 50000;
            //Check type 20k
            temp = amount % 20000;
            loai50 = Convert.ToInt32((amount - temp) / 20000);
            if (ATM_loai20< loai20)
            {
                loai20 = ATM_loai20;
            }
            amount = amount - loai20 * 20000;
            //Check type 10k
            temp = amount % 10000;
            loai10 = Convert.ToInt32((amount - temp) / 10000);
            if (ATM_loai10< loai10)
            {
                loai10 = ATM_loai10;
            }
            amount = amount - loai10 * 10000;

            if (amount > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        //Rút thành công
        [TestMethod]
        public void UC2CheckInATM1()
        {
            bool check = CheckMoneyInATM(300000, 0, 0, 5, 3, 3, 0);
            Assert.AreEqual(check, true);
        }

        //Rút 500k nhưng cây ATM còn toàn loại 200k
        [TestMethod]
        public void UC2CheckInATM2()
        {
            bool check = CheckMoneyInATM(500000, 0, 5, 0, 0, 0, 0);
            Assert.AreEqual(check, false);
        }

        //Rút 200k nhưng cây ATM không còn đủ loại tiền ghép 200k
        [TestMethod]
        public void UC2CheckInATM3()
        {
            bool check = CheckMoneyInATM(200000, 10, 0, 1, 1, 1, 1);
            Assert.AreEqual(check, false);
        }

        //Tổng tiền trong cây ATM không đủ
        [TestMethod]
        public void UC2CheckInATM4()
        {
            bool check = CheckMoneyInATM(2000000, 3, 1, 1, 1, 1, 1);
            Assert.AreEqual(check, false);
        }
        #endregion

        #region TestAll    
        public Boolean CheckAll(decimal amount)
        {
            if (ValidateAmount(amount) == true 
                && CheckBalane(amount,1000000)
                && CheckMoneyInATM(amount, 10, 2, 0, 0, 2, 2) == true)
            {
                return true;
            }
            else 
            {
                return false;
            }
        }

        //Số tiền lớn hơn 5 triệu
        [TestMethod]
        public void UC2TestAll1()
        {
            bool check = CheckAll(20000000);
            Assert.AreEqual(check, false);
        }

        //Số tiền nhỏ hơn 50k(không phải bội số 50k)
        [TestMethod]
        public void UC2TestAll2()
        {
            bool check = CheckAll(10000);
            Assert.AreEqual(check, false);
        }

        //Số tiền nhiều hơn trong tài khoản
        [TestMethod]
        public void UC2TestAll3()
        {
            bool check = CheckAll(2000000);
            Assert.AreEqual(check, false);
        }

        //Thành công
        [TestMethod]
        public void UC2TestAll4()
        {
            bool check = CheckAll(1000000);
            Assert.AreEqual(check, true);
        }

        //Tiền trong cây ATM không đủ để ghép 300k
        [TestMethod]
        public void UC2TestAll5()
        {
            bool check = CheckAll(300000);
            Assert.AreEqual(check, false);
        }

        //Tiền trong cây ATM không đủ để ghép 300k
        [TestMethod]
        public void UC2TestAll6()
        {
            bool check = CheckAll(100000);
            Assert.AreEqual(check, false);
        }
        #endregion
    }
}
